﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SQL_Manager
{
    public partial class frmMain : Form
    {

        public frmMain()
        {
            InitializeComponent();
        }

        //
        // If the database is connected, confirm exit
        //
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Database Db;
            Database.GetInstance(out Db);

            if (Db != null && Db.connected())
            {
                DialogResult _Dr = MessageBox.Show(this, "Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2);

                if (_Dr == DialogResult.Yes)
                {
                    this.Close();
                }

                return;
            }
            this.Close();
        }

        private void runToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form _f = new frmPlayerLookup{ MdiParent=this };
            _f.Show();
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (this.btnConnect.Text.Equals("Disconnect"))
            {
                Database Db;
                Database.GetInstance(out Db);

                Db.close();
                this.btnConnect.Text = "Connect";
                this.btnConnect.Image = SQL_Manager.Properties.Resources.Network;
            }
            else
            {
                DialogResult _Dr = new frmConnect().ShowDialog();

                if (_Dr == DialogResult.OK)
                {
                    this.btnConnect.Text = "Disconnect";
                    this.btnConnect.Image = SQL_Manager.Properties.Resources.Delete;
                }
            }
        }

        private void fileMenuToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.mnuFile.Visible = this.fileMenuToolStripMenuItem.Checked;
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Form _f = new frmPlayerLookup { MdiParent = this };
            _f.Show();
        }

        private void toolStrip4_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            OTServ.Position p = new SQL_Manager.OTServ.Position
            {
                x = 100,
                y = 100,
                z = 5
            };
        }

        private void toolStripPanel1_Click(object sender, EventArgs e)
        {

        }
    }
}
